
package midas.mw.crt.common;

// Context Based Message
public class CBMessage 
{
	// TODO: destination argument should be of ContextAddress type
	private	String destination= null;
	private byte[] payload;
	private int flags;
	private long timestamp;
	private static int hashgen;
	private final int hashcode;

	public CBMessage(String destination_in, byte[] payload_in, int flags_in)
	{
		destination = destination_in;
		payload = payload_in;
		flags = flags_in;
		hashcode = hashgen;;
		hashgen++;
	}

	public String getDestination()
	{
		return destination;
	}
	
	public byte[] getPayload()
	{
		return payload;
	}

	public int getFlags()
	{
		return flags;
	}

	public void setTimestamp()
	{
		timestamp = System.currentTimeMillis();
	}

	public long getTimestamp()
	{
		return timestamp;
	}

	public int hashCode()
	{
		return hashcode;
	}

	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final CBMessage other = (CBMessage) obj;
		return hashcode == other.hashCode();
	}
}
